package com.xxxx.springboot.shiro.config;

import java.util.concurrent.atomic.AtomicInteger;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;
import org.springframework.stereotype.Component;

@Component
public class MySessionListener implements SessionListener {
	/**
	 * 统计在线人数 juc包下线程安全自增
	 */
	private final AtomicInteger sessionCount = new AtomicInteger(0);

	@Override
	public void onStart(Session session) {
		sessionCount.incrementAndGet();
		// session.getAttribute(key)
		System.out.println("登陆+1==" + sessionCount.get());
	}

	@Override
	public void onStop(Session session) {
		sessionCount.decrementAndGet();
		System.out.println("登陆-1==" + sessionCount.get());
	}

	@Override
	public void onExpiration(Session session) {
		sessionCount.decrementAndGet();

		System.out.println("登陆过期-1==" + sessionCount.get());
	}
}